<!--
 * @Author: MrLee
 * @Date: 2024-08-23 23:46:53
 * @LastEditors: MrLee
 * @LastEditTime: 2024-09-14 09:36:58
 * @Description: 请填写简介
-->
<template>
  <view>
    <custom-navbar :title="title" :autoBack="true" leftIconColor="#303133" />
    <Tabbar :tab-list="tabList" fontSize="30rpx" defaultFontSize="26rpx" />
    <up-gap height="30rpx" />
    <enterpriseList :job-list="jobList" />
  </view>
</template>
<script lang="ts" setup>
import enterpriseList from "@/pages/components/enterprise-list/index.vue";
import Tabbar from "@/pages/components/tabbar/index.vue";
import { userJobList, hrLookJobCount } from "@/api/user";

let title = ref('')

const tabList:any = ref([
  { name: "全部(0)", activeLineWidth: "144" },
  { name: "招聘中(0)", activeLineWidth: "180" },
  { name: "未过审(0)", activeLineWidth: "180" },
  { name: "已关闭(0)", activeLineWidth: "180" },
]);
async function getJobCount() {
  let r = await hrLookJobCount();
  console.log('职位管理/招聘统计 数量 r:::', r);
  if (!r){
    uni.showToast({title: "暂无招聘信息"})
    return
  }
  tabList.value = [
    { name: "全部("+r.total_count+")", activeLineWidth: "144" },
    { name: "招聘中("+r.open_count+")", activeLineWidth: "180" },
    { name: "未过审("+r.check_count+")", activeLineWidth: "180" },
    { name: "已关闭("+r.close_count+")", activeLineWidth: "180" },
  ]
  console.log('数量：：：', tabList)
}

const jobList: any = reactive([]);
async function getJobList(status : number = 0) {
  let params : any = {
    status: 1
  }
  if (status > 0) {
    params['status'] = status
  }
  let result = await userJobList(params);
  console.log('职位管理/在招职位列表 res list:::', result);
  //vue3传递result的值到子组件JobList中的属性jobList中
  jobList.splice(0, jobList.length);
  for (let i = 0; i < result.list.length; i++) {
    const r = result.list[i]
    let rr = {
      job_name: r.name,
      job_id: r.id,
      salary_min: r.salary_min,
      salary_max: r.salary_max,
      salary_count: r.salary_count,
      province: r.province.name,
      city: r.city.name,
      job_nature: r.nature,
      qualifications: '',
      status: r.status,
      status_name: r.status == 1 ? '招聘中' : r.status == 2 ? '未过审' : '已关闭',
      company_id: r.company.id,
      company_logo: r.company.url_logo,
      company_name: r.company.name,
      company_type: r.company.type == 1 ? '民营' : r.company.type == 2 ? '国企' : '合资',
      company_listed: r.company.listed == 1 ? '未上市' : '上市',
    }
    let qualifications = ''
    for (let j = 0; j < r.qualifications.length; j++) {
      qualifications += r.qualifications[j] + ' '
    }
    rr.qualifications = qualifications
    jobList.push(rr)
  }
}
onLoad((e) => {
  title.value = e.type == "1" ? "在招职位" : "职位管理";
  getJobCount();
  getJobList();
});
</script>

